<?php
class PhieukiemkesController extends AppController {

	var $name = 'Phieukiemkes';

	function index() {
		$this->Phieukiemke->recursive = 0;
		$this->set('phieukiemkes', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid phieukiemke', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('phieukiemke', $this->Phieukiemke->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Phieukiemke->create();
			if ($this->Phieukiemke->save($this->data)) {
				$this->Session->setFlash(__('The phieukiemke has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The phieukiemke could not be saved. Please, try again.', true));
			}
		}
        $this->Phieukiemke->Canbo->displayField="ten";
		$canbos = $this->Phieukiemke->Canbo->find('list');
        $this->Phieukiemke->Loaikiemke->displayField="tenloai";
		$loaikiemkes = $this->Phieukiemke->Loaikiemke->find('list');
		$this->set(compact('canbos', 'loaikiemkes'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid phieukiemke', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Phieukiemke->save($this->data)) {
				$this->Session->setFlash(__('The phieukiemke has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The phieukiemke could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Phieukiemke->read(null, $id);
		}
	  $this->Phieukiemke->Canbo->displayField="ten";
		$canbos = $this->Phieukiemke->Canbo->find('list');
        $this->Phieukiemke->Loaikiemke->displayField="tenloai";
		$loaikiemkes = $this->Phieukiemke->Loaikiemke->find('list');
		$this->set(compact('canbos', 'loaikiemkes'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for phieukiemke', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Phieukiemke->delete($id)) {
			$this->Session->setFlash(__('Phieukiemke deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Phieukiemke was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
